package org.leumasjaffe.util;

/**
 * A class that represents an ordered pair of Objects
 * @author Sam Jaffe
 *
 * @param <T> Class of the first piece of data
 * @param <S> Class of the second piece of data
 */
public class Pair <T, S>{
	private T first;
	private S second;
	
	public Pair (T t, S s) {
		this.first = t;
		this.second = s;
	}
	
	public Pair() {
	}

	public void setFirst(T first) {
		this.first = first;
	}
	
	public T getFirst() {
		return this.first;
	}
	
	public void setSecond(S second) {
		this.second = second;
	}
	
	public S getSecond() {
		return this.second;
	}
	
	public static <T, S> Pair<T, S> makePair(T first, S second) {
		return new Pair<T, S>(first, second);
	}
	
	@Override
	public boolean equals(Object o) {
		if (o instanceof Pair) {
			return this.first.equals(((Pair<?, ?>) o).getFirst()) && 
					this.second.equals(((Pair<?, ?>) o).getSecond());
		}
		return false;
	}
	
	@Override
	public int hashCode() {
		return 17 * this.first.hashCode() + 23 * this.second.hashCode();
	}
	
	@Override
	public String toString() {
		return "(" + this.first.toString() + ", " + this.second.toString() + ")";
	}
	
}
